<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>XXForm 登录</title>
    <script th:src="@{/js/main.js}"></script>
    <style>
        body {
            background-color: #e6e6e6;
            /*background: url('/images/background.png') no-repeat;*/
            background-size: 100% auto;
            margin: 0;
        }
        .logo {
            width: 120px;
            display: inline-block;
            margin-top: -8px;
            margin-bottom: -12px;
            margin-right: 20px;
        }
        .title {
            font-size: 18px;
            padding: 20px 70px;
            color: rgb(0, 122, 47);
            font-weight: bold;
            background-color: rgba(255, 255, 255, 0.8);
            box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1);
        }
        .version {
            font-size: 12px;
            color: #666;
        }
        .panel {
            position: fixed;
            top: 20%;
            left: 5%;
            width: 360px;
            padding: 40px;
            box-sizing: border-box;
            background-color: rgba(255, 255, 255, 0.8);
            box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
        }
        .tips {
            color: #666;
        }
        label {
            font-size: 12px;
            color: #666;
            display: block;
        }
        input {
            border: 1px solid #555;
            width: 100%;
            padding: 10px;
            margin-top: 6px;
            box-sizing: border-box;
            outline: none;
        }
        input:focus {
            border-color: rgb(0, 122, 47);
        }
        .login {
            border: 1px solid rgb(0, 122, 47);
            background-color: rgb(0, 122, 47);
            outline: none;
            box-sizing: border-box;
            padding: 10px 40px;
            color: #fff;
            font-size: 14px;
            border-radius: 20px;
        }
        .login:hover {
            opacity: 0.8;
        }
        .footer {
            font-size: 12px;
            color: #666;
            position: fixed;
            left: 0;
            right: 0;
            text-align: center;
            bottom: 10px;
        }
        .switch {
            color: rgb(0, 122, 47);
            font-size: 12px;
        }
    </style>
</head>
<body>
    <div class="title">
        <!--<img th:src="@{/images/logo2.png}" class="logo"/>-->
        XXForm 在线问卷调研系统
    </div>
    <div class="panel" id="container">
        <div class="tips">
            XXForm ·
            <span v-show="mode==1">登录</span>
            <span v-show="mode==2">注册</span>
        </div>
        <div class="form">
            <p>
                <label>账号：<small>（手机号或者邮箱地址）</small></label>
                <input type="text" ref="account" v-model="account" />
            </p>
            <p>
                <label>密码：</label>
                <input type="password" ref="password" v-model="password" v-if="mode==1" />
                <input type="text" ref="password" v-model="password" v-if="mode==2" />
            </p>
            <p><a href="javascript:;" class="switch" @click="mode=mode==1?2:1">
                <span v-show="mode==1">还没有账号？立即注册</span>
                <span v-show="mode==2">有账号？立即登录</span>
            </a></p>
            <p style="text-align: center;padding-top: 20px;">
                <button type="button" class="login" @click="login">
                    <span v-show="mode==1">登录</span>
                        <span v-show="mode==2">注册</span>
                </button>
            </p>
        </div>
    </div>
    <div class="footer">
        <p>&copy; Copyright 2023 <b style="color: rgb(0, 122, 47)">蓝欣科技</b> <b><a href="https://beian.miit.gov.cn/" target="_blank" style="color: #555;">沪ICP备2023xxxxxx号</a></b> 
            &nbsp;&nbsp; Version: <b class="version" th:text="${appVersion}"></b>
        </p>
    </div>
    <script th:src="@{/js/vue-min.js}"></script>
    <script>
        const vue = new Vue({
            el: '#container',
            data: {
                account: '',
                password: '',
                mode: 1
            },
            methods: {
                baseCheck: function () {
                    if (this.account == '') {
                        alert('请填写账号');
                        this.$refs['account'].focus();
                        return false;
                    }
                    if (this.code == '') {
                        alert('请填写密码');
                        this.$refs['password'].focus();
                        return false;
                    }
                    return true;
                },
                login: function () {
                    if (vue.baseCheck()) {
                        
                        lets.post('/user/'+(this.mode==1?'login':'register')+'.do', {
                            account: this.account,
                            password: this.password
                        }).then(res => {
                            if (res.code == 1) {
                                if (this.mode == 2) {
                                    alert('注册成功');
                                    this.mode = 1;
                                } else {
                                    location.href = '/home';
                                }
                            } else {
                                alert(res.error);
                                this.password = '';
                            }
                        });
                    }
                }
            }
        });
    </script>
</body>
</html>